#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;

template<class T>
class Stack
{
    public:
        Stack(){
            element = new T[10];
            top = 0;
            capacity = 10;
        }
        Stack(int size){
            element = new T[size];
            top = 0;
            capacity = size;
        }
        ~Stack(){
            element = nullptr;
        };
        void clear(){
            top = 0;
        }
        void resize(){
            if(this->top < this->capacity * this->factor){
                return;
            }
            int nc = this->capacity + (int)(this->capacity * factor) + 1;
            T * ne = new T[nc];
            for(int i=0; i<this->top; i++){
                ne[i] = this->element[i];
            }
            this->element = nullptr;
            this->element = ne;
            this->capacity = nc;
            ne = nullptr;
            cout<<"resize "<<this->capacity<<endl;
        }
        void push(T data){
            resize();
            if(top == capacity){
                cout<<"stack is full\n";
                return;
            }
            element[top] = data;
            ++top;
        }
        T pop(){
            if(isEmpty()){
                return T{};
            }
            T data = element[--top];
            return data;
        }
        bool isEmpty(){
            return top == 0;
        }

    private:
        T *element;
        int top;
        int capacity;
        float factor = 0.75f;
};

#endif // STACK_H